﻿#include "CPdfRptDataPkg.h"
#include <QDir>
#include "CTaskExecInfo.h"
#include "CHeader.h"
#include <QSqlRecord>
CPdfRptDataPkg::CPdfRptDataPkg(QObject *parent)
	: QObject(parent)
{

}

CPdfRptDataPkg::~CPdfRptDataPkg()
{

}

//组包公共数据
bool CPdfRptDataPkg::pkgPubPdfRptData(QDateTime dtSearchStartTime, QDateTime dtSearchEndTime, QString sSynPdfFolderPath, QString sHttpPrefix, QString sRobName, QString sBeltNameOri, CAllPdfRptDataInfo &dataInfo, QString &sErrMsg)
{
	dataInfo.pubDataInfo.m_sSynBeltName = sBeltNameOri;//综合检测皮带名称
	dataInfo.pubDataInfo.m_sSynDate = dtSearchStartTime.toString("yyyy-MM-dd");//综合检测日期(2025-02-25)
	dataInfo.pubDataInfo.m_sSynStartTime = dtSearchStartTime.toString("yyyy-MM-dd hh:mm:ss");//综合检测开始时间(10:15:00)
	dataInfo.pubDataInfo.m_sSynEndTime = dtSearchEndTime.toString("yyyy-MM-dd hh:mm:ss");//综合检测结束时间(12:30:10)

	//当前系统时间
	QDateTime dtCurTime = QDateTime::currentDateTime();
	QString strCurrTime = dtCurTime.toString("yyyyMMddhhmmss");
	//创建文件夹
	QString strFolder = sSynPdfFolderPath + "Result/Synth/" + sRobName + "/" + QDateTime::currentDateTime().toString("yyyyMM") + "/";//文件夹+机器人名称组合+年月
	QDir folder(strFolder);// 创建QDir对象
	if (!folder.exists())
	{
		// 文件夹不存在，则创建
		if (folder.mkpath("."))
		{
		}
		else
		{
		}
	}
	else
	{

	}

	//输出路径
	QString sOutPath = strFolder + strCurrTime + A2T("综合报告.pdf");//综合报表本地路径

	QString sPathTemp = sOutPath;
	QString sPdfPathUrl = sHttpPrefix + sPathTemp.remove(sSynPdfFolderPath);
	QString sSynthPdfPathUrl = sPdfPathUrl.replace("#", "%23");//综合报表URL路径

	dataInfo.pubDataInfo.m_sOutputSynPdfFolder = sOutPath;
	dataInfo.pubDataInfo.m_sOutputSynPdfUrl = sSynthPdfPathUrl;

	//查询皮带表 查看该皮带包含的模块 用于综合报表显示这些模块
	{
		QString sIncludeDev = ""; //包含设备用 - 分隔(1机器人 2纠偏 3撕裂 4其他AI检测 5声振温 6球机)
		//CSqlOperPub::instance().getBeltIncDev(sBeltNameOri, sIncludeDev, sErrMsg);
		if (sIncludeDev.size() > 0)
		{
			QStringList sDevlist = sIncludeDev.split("-");
			for (int i = 0; i < sDevlist.size(); i++)
			{
				int nDevId = sDevlist.at(i).toInt();
				switch (nDevId)
				{
				case enBeltIncRob:
					dataInfo.pubDataInfo.m_bSynIncRob = true;
				case enBeltIncRec:
					dataInfo.pubDataInfo.m_bSynIncRec = true;
				case enBeltIncTear:
					dataInfo.pubDataInfo.m_bSynIncTear = true;
				case enBeltIncRestAi:
					dataInfo.pubDataInfo.m_bSynIncRestAi = true;
				case enBeltIncSese:
					dataInfo.pubDataInfo.m_bSynIncSese = true;
				case enBeltIncBaCam:
					dataInfo.pubDataInfo.m_bSynIncBaCam = true;
				default:
					break;
				}
			}
		}
		
	}


	return true;
}

//组包机器人数据
bool CPdfRptDataPkg::pkgRobPdfRptData(CTaskExecInfo* pTaskExecInfo, QString sRobName, QString sPdfFolderPath, QString sHttpPrefix, QString sClientCompanyName, CAllPdfRptDataInfo &dataInfo, QString &sErrMsg)
{
	//=====================================组装连续检测信息=========================================
#if 1
	int nCotNormalNUmber = 0;//连续检测正常项数
	int nCotAlmNumber = 0;//连续检测异常项数
	//遍历所有巡检项,找到连续检测的所有起点和中间点,找到里面的vec数据
	for (int i = 0; i < pTaskExecInfo->m_vecPolItemCom.size(); i++)
	{
		int nDevType = pTaskExecInfo->m_vecPolItemCom[i]->m_pPolItem->m_nDevTypeCode;//取出 巡检项设备类型编码  
		if (nDevType == enVoice || nDevType == enIR || nDevType == enCamer)//取出连续检测的类型
		{
			CPolItemCamer *pPolItemCamer = (CPolItemCamer*)pTaskExecInfo->m_vecPolItemCom[i]->m_pPolItem;
			if (pPolItemCamer == nullptr)
			{
				continue;
			}

			if (pPolItemCamer->m_nCheckType == 1 && (pPolItemCamer->m_nCollectIndex == 0 || pPolItemCamer->m_nCollectIndex == 2))//筛选出 持续任务主动上报类型 && 所有起点或者中间点
			{
				for (int j = 0; j < pTaskExecInfo->m_vecPolItemCom[i]->m_vecItemResult.size(); j++)//遍历连续检测结果
				{
					CItemResultCamera *pItemResultCamer = (CItemResultCamera *)pTaskExecInfo->m_vecPolItemCom[i]->m_vecItemResult[j];

					if (pItemResultCamer == nullptr)
					{
						continue;
					}

					CSingleCotDetInfo singleCotDetInfo;
					//基础数据
					singleCotDetInfo.eItemCode = static_cast<EDevTypeCode>(pItemResultCamer->m_nDevTypeCode);//巡检项类型(红外、声音、图像)

					singleCotDetInfo.m_dLocation = pItemResultCamer->m_dRealLocation;//位置(m)
					singleCotDetInfo.m_nRollerCode = pItemResultCamer->m_nRollerNum;//托辊号
					singleCotDetInfo.m_sRollerDesc = pItemResultCamer->m_sRollerDesc;//托辊号描述
					singleCotDetInfo.m_nAlmState = pItemResultCamer->m_nState;//报警状态 0:正常 1:高报 2:高高报 -1:低报 -2:低低报
					if (singleCotDetInfo.m_nAlmState == 0)//正常
					{
						nCotNormalNUmber += 1;
					}
					else if (singleCotDetInfo.m_nAlmState == -1 || singleCotDetInfo.m_nAlmState == -2 || singleCotDetInfo.m_nAlmState == 1 || singleCotDetInfo.m_nAlmState == 2)//异常
					{
						nCotAlmNumber += 1;
					}
					else
					{
						//未执行不考虑
					}
					singleCotDetInfo.m_dtActionTime = pItemResultCamer->m_dActionTime;//执行时间
					singleCotDetInfo.m_sHttpPicAddr = pItemResultCamer->m_sHttpUrl;//http图片地址

					//差异数据
					if (nDevType == enIR)//红外
					{
						singleCotDetInfo.m_doMeasurementVal = pItemResultCamer->m_dTempMax;//测量数值 使用最高温度

						if (-2 == pItemResultCamer->m_nState)
						{
							singleCotDetInfo.m_strAlmDesc = A2T("小于低低限");
							singleCotDetInfo.m_sRemark = A2T("低低限%1%2").arg(pItemResultCamer->m_sDataThreadHoldLL).arg(A2T("℃"));
						}
						else if (-1 == pItemResultCamer->m_nState)
						{
							singleCotDetInfo.m_strAlmDesc = A2T("小于低限");
							singleCotDetInfo.m_sRemark = A2T("低限%1%2").arg(pItemResultCamer->m_sDataThreadHoldL).arg(A2T("℃"));
						}
						else if (0 == pItemResultCamer->m_nState)
						{
							singleCotDetInfo.m_strAlmDesc = A2T("正常");
							singleCotDetInfo.m_sRemark = A2T("高限%1%2").arg(pItemResultCamer->m_sDataThreadHoldH).arg(A2T("℃"));
						}
						else if (1 == pItemResultCamer->m_nState)
						{
							singleCotDetInfo.m_strAlmDesc = A2T("超高限");
							singleCotDetInfo.m_sRemark = A2T("高限%1%2").arg(pItemResultCamer->m_sDataThreadHoldH).arg(A2T("℃"));
						}
						else if (2 == pItemResultCamer->m_nState)
						{
							singleCotDetInfo.m_strAlmDesc = A2T("超高高限");
							singleCotDetInfo.m_sRemark = A2T("高高限%1%2").arg(pItemResultCamer->m_sDataThreadHoldHH).arg(A2T("℃"));
						}

						singleCotDetInfo.m_sPictureRemark = A2T("平均温度:%1℃\n最低温度:%2℃\n最高温度:%3℃").arg(pItemResultCamer->m_dTempAverage).arg(pItemResultCamer->m_dTempMin).arg(pItemResultCamer->m_dTempMax);
						singleCotDetInfo.m_sPictureAddress = pItemResultCamer->m_sIRUrl;//本地图片地址
					}
					else if (nDevType == enCamer)//图像相机
					{
						singleCotDetInfo.m_nAlmState = 0;//图像相机默认正常
						singleCotDetInfo.m_sPictureRemark = A2T("/");;//图片备注为空
						singleCotDetInfo.m_sPictureAddress = pItemResultCamer->m_sIRUrl;//本地图片地址

					}
					else if (nDevType == enVoice)//声音传感器
					{
						singleCotDetInfo.m_doMeasurementVal = pItemResultCamer->m_dValue;//噪声值

						if (-2 == pItemResultCamer->m_nState)
						{
							singleCotDetInfo.m_strAlmDesc = A2T("小于低低限");
							singleCotDetInfo.m_sRemark = A2T("低低限:%1%2").arg(QString::number(pItemResultCamer->m_sDataThreadHoldLL.toDouble(), 'f', 1)).arg(A2T("dB"));//备注
						}
						else if (-1 == pItemResultCamer->m_nState)
						{
							singleCotDetInfo.m_strAlmDesc = A2T("小于低限");
							singleCotDetInfo.m_sRemark = A2T("低限:%1%2").arg(QString::number(pItemResultCamer->m_sDataThreadHoldL.toDouble(), 'f', 1)).arg(A2T("dB"));//备注
						}
						else if (0 == pItemResultCamer->m_nState)
						{
							singleCotDetInfo.m_strAlmDesc = A2T("正常");
							singleCotDetInfo.m_sRemark = A2T("高限:%1%2").arg(QString::number(pItemResultCamer->m_sDataThreadHoldH.toDouble(), 'f', 1)).arg(A2T("dB"));//备注
						}
						else if (1 == pItemResultCamer->m_nState)
						{
							singleCotDetInfo.m_strAlmDesc = A2T("超高限");
							singleCotDetInfo.m_sRemark = A2T("高限:%1%2").arg(QString::number(pItemResultCamer->m_sDataThreadHoldH.toDouble(), 'f', 1)).arg(A2T("dB"));//备注
						}
						else if (2 == pItemResultCamer->m_nState)
						{
							singleCotDetInfo.m_strAlmDesc = A2T("超高高限");
							singleCotDetInfo.m_sRemark = A2T("高高限:%1%2").arg(QString::number(pItemResultCamer->m_sDataThreadHoldHH.toDouble(), 'f', 1)).arg(A2T("dB"));//备注
						}
					}


					dataInfo.robDataInfo.m_VecCotDetInfo.push_back(singleCotDetInfo);//塞入 连续检测数据集合

				}
			}

		}

	}
#endif

	//==================组装普通信息=====================
	//=======机器人数据======
	dataInfo.robDataInfo.m_sClientCompanyName = sClientCompanyName;//客户电厂名称
	dataInfo.robDataInfo.m_sTaskActionId = pTaskExecInfo->m_sTaskExecGuid;//子任务Id(用于更新数据库中的pdf存储地址)
	dataInfo.robDataInfo.m_sRobotName = sRobName;//机器人名称 "南电#1机器人"
	dataInfo.robDataInfo.m_sTaskName = pTaskExecInfo->m_sTaskName;//巡检任务名称 "全面巡检任务"
	dataInfo.robDataInfo.m_sTaskTime = pTaskExecInfo->m_sStartTime;//巡检日期
	dataInfo.robDataInfo.m_sComment = "";//备注
	dataInfo.robDataInfo.m_sTaskStartTime = pTaskExecInfo->m_sStartTime;//任务开始时间 "09:00:00"
	dataInfo.robDataInfo.m_sTaskEndTime = pTaskExecInfo->m_sEndTime;//任务结束时间 "09:30:00"
	dataInfo.robDataInfo.m_sTaskStartElecVal = QString::number(pTaskExecInfo->m_dStartPower);//任务开始电量"80%"
	dataInfo.robDataInfo.m_sTaskEndElecVal = QString::number(pTaskExecInfo->m_dEndPower);//任务开始电量"80%"
	dataInfo.robDataInfo.m_sTaskState = pTaskExecInfo->m_sTaskExecDes;//任务状态
	//组装巡检点信息(包含巡检项)
	//使用巡检点来包含巡检项 (CFormInspectionPointInfo 这个巡检点管理数组)
	QMap<QString, CFormInspectionPointInfo> mapFormInspectionPointInfo;// QString:巡检点Guid  CFormInspectionPointInfo:输出pdf巡检点全部信息
	for (int i = 0; i < pTaskExecInfo->m_vecPolItemCom.size(); i++)//遍历巡检项,创建巡检点Map
	{
		//排除连续检测巡检项类型
		if (pTaskExecInfo->m_vecPolItemCom[i]->m_ItemResult->m_nDevType == 1)//云台
		{
			CPolItemCamer* pPolItemCamerData = (CPolItemCamer*)pTaskExecInfo->m_vecPolItemCom[i]->m_pPolItem;
			//首先如果是持续监测主动上报的巡检项，则跳过
			if (pPolItemCamerData->m_nCheckType == 1)
			{
				continue;
			}
		}


		//先找出巡检点id
		CPolPoint *pPointTemp = pTaskExecInfo->m_vecPolItemCom[i]->m_pPolPoint;
		QString sPointGuid = pPointTemp->m_sPointGuid;
		//赋值巡检点基本信息
		CFormInspectionPointInfo FormPointInfo;
		FormPointInfo.m_douPointSortIndex = i;//排序号(不显示在表格里,用于给巡检点排序的)
		FormPointInfo.m_strInspectionPointName = pPointTemp->m_sPointName;//巡检点名称
		FormPointInfo.m_nRollerCode = pPointTemp->m_nRollerCode;//托辊号
		FormPointInfo.m_sRollerDesc = pPointTemp->m_sRollerDesc;//托辊描述信息
		FormPointInfo.m_strRobotName = sRobName;//机器人名称
		//double ddd = pPointTemp->m_dPointLocation / 1000;

		FormPointInfo.m_strLocation = A2T("%1m").arg(QString::number(pPointTemp->m_dPointLocation / 1000, 'f', 1));//位置 需要除以1000换算


		FormPointInfo.m_dLocation = pPointTemp->m_dPointLocation;
		if (pTaskExecInfo->m_vecPolItemCom[i]->m_ItemResult->m_nDevType == 1)//云台
		{
			CItemResultCamera *pCamerResult = (CItemResultCamera *)pTaskExecInfo->m_vecPolItemCom[i]->m_ItemResult;
			FormPointInfo.m_strInspectDate = pCamerResult->m_dActionTime.toString("yyyy-MM-dd");//巡检日期 2023-11-13
			FormPointInfo.m_strInspectTime = pCamerResult->m_dActionTime.toString("hh:mm:ss");;//巡检时间 09:04:00
		}
		else if (pTaskExecInfo->m_vecPolItemCom[i]->m_ItemResult->m_nDevType == 0)//本体传感器
		{
			CItemResultSensor *pSensorResult = (CItemResultSensor *)pTaskExecInfo->m_vecPolItemCom[i]->m_ItemResult;
			FormPointInfo.m_strInspectDate = pSensorResult->m_dActionTime.toString("yyyy-MM-dd");//巡检日期 2023-11-13
			FormPointInfo.m_strInspectTime = pSensorResult->m_dActionTime.toString("hh:mm:ss");;//巡检时间 09:04:00
		}
		FormPointInfo.m_strRemark = "";//备注(暂时为空，预留)

		if (!mapFormInspectionPointInfo.contains(sPointGuid))
		{
			mapFormInspectionPointInfo.insert(sPointGuid, FormPointInfo);
		}
		else
		{
			//如果选检点GUid相同,需要判断托辊描述信息包含
			if (FormPointInfo.m_sRollerDesc.size() > 0)//托辊描述不为空
			{
				if (!mapFormInspectionPointInfo[sPointGuid].m_sRollerDesc.contains(FormPointInfo.m_sRollerDesc))
				{
					//如果不包含 需要追加
					mapFormInspectionPointInfo[sPointGuid].m_sRollerDesc += "-";
					mapFormInspectionPointInfo[sPointGuid].m_sRollerDesc += FormPointInfo.m_sRollerDesc;
				}
			}

		}
	}

	//给巡检点Map中的各个巡检项归位
	for (int i = 0; i < pTaskExecInfo->m_vecPolItemCom.size(); i++)//遍历巡检项,巡检项归位巡检点中
	{
		if (false == pTaskExecInfo->m_vecPolItemCom[i]->m_bIsAction)//未执行的巡检项不展示
		{
			continue;
		}

		//先找出巡检点id
		CPolPoint *pPointTemp = pTaskExecInfo->m_vecPolItemCom[i]->m_pPolPoint;
		QString sPointGuid = pPointTemp->m_sPointGuid;

		if (pTaskExecInfo->m_vecPolItemCom[i]->m_ItemResult->m_nDevType == 1)//云台
		{
			//目前输出红外、图像、声音
			CItemResultCamera *pCamerResult = (CItemResultCamera *)pTaskExecInfo->m_vecPolItemCom[i]->m_ItemResult;
			if (1 == pCamerResult->m_nCheckType)//如果是持续任务上报类型,作为起点、中间点、终点啥的不展示
			{
				continue;
			}

			//基础数据
			CPdfOutInspecItemInfoAll itemInfo;
			itemInfo.m_sItemName = pCamerResult->m_sItemName;//巡检项名称
			itemInfo.m_sHttpPicAddr = pCamerResult->m_sHttpUrl;//http图片地址

			//特殊数据
			if (pCamerResult->m_nDevTypeCode == enIR)
			{
				itemInfo.eItemType = enIR;
				itemInfo.m_doMeasurementVal = pCamerResult->m_dTempMax;//测量数值 使用最高温度
				itemInfo.m_sUnit = A2T("℃");

				if (-2 == pCamerResult->m_nState)
				{
					itemInfo.m_sState = A2T("小于低低限");
					itemInfo.m_bStateOk = false;
					itemInfo.m_sRemark = A2T("低低限%1%2").arg(pCamerResult->m_sDataThreadHoldLL).arg(itemInfo.m_sUnit);
				}
				else if (-1 == pCamerResult->m_nState)
				{
					itemInfo.m_sState = A2T("小于低限");
					itemInfo.m_bStateOk = false;
					itemInfo.m_sRemark = A2T("低限%1%2").arg(pCamerResult->m_sDataThreadHoldL).arg(itemInfo.m_sUnit);
				}
				else if (0 == pCamerResult->m_nState)
				{
					itemInfo.m_sState = A2T("正常");
					itemInfo.m_bStateOk = true;
					//正常显示高限
					itemInfo.m_sRemark = A2T("高限%1%2").arg(pCamerResult->m_sDataThreadHoldH).arg(itemInfo.m_sUnit);
				}
				else if (1 == pCamerResult->m_nState)
				{
					itemInfo.m_sState = A2T("超高限");
					itemInfo.m_bStateOk = false;
					itemInfo.m_sRemark = A2T("高限%1%2").arg(pCamerResult->m_sDataThreadHoldH).arg(itemInfo.m_sUnit);
				}
				else if (2 == pCamerResult->m_nState)
				{
					itemInfo.m_sState = A2T("超高高限");
					itemInfo.m_bStateOk = false;
					itemInfo.m_sRemark = A2T("高高限%1%2").arg(pCamerResult->m_sDataThreadHoldHH).arg(itemInfo.m_sUnit);
				}
				else if (-10 == pCamerResult->m_nState)
				{
					itemInfo.m_sState = A2T("未执行");
					itemInfo.m_bStateOk = false;
					itemInfo.m_sRemark = A2T("未执行");
				}

				itemInfo.m_sPictureRemark = A2T("平均温度:%1℃\n最低温度:%2℃\n最高温度:%3℃").arg(pCamerResult->m_dTempAverage).arg(pCamerResult->m_dTempMin).arg(pCamerResult->m_dTempMax);
				itemInfo.m_sPictureAddress = pCamerResult->m_sIRUrl;//图片本地地址
			}
			else if (pCamerResult->m_nDevTypeCode == enCamer)
			{
				itemInfo.eItemType = enCamer;
				if (1 == pCamerResult->m_nState)
				{
					itemInfo.m_sState = A2T("报警");
					itemInfo.m_bStateOk = false;
					itemInfo.m_sRemark = A2T("");

					itemInfo.m_sPictureRemark = pCamerResult->m_sDataDesc;
				}
				else
				{
					itemInfo.m_sState = A2T("/");
					itemInfo.m_bStateOk = true;
					itemInfo.m_sRemark = A2T("");

					itemInfo.m_sPictureRemark = A2T("/");
				}

				itemInfo.m_sPictureAddress = pCamerResult->m_sIRUrl;//图片本地地址

			}
			else if (pCamerResult->m_nDevTypeCode == enVoice)
			{
				itemInfo.eItemType = enVoice;
				itemInfo.m_doMeasurementVal = pCamerResult->m_dValue;//测量数值
				itemInfo.m_sUnit = A2T("dB");//单位

				if (-2 == pCamerResult->m_nState)
				{
					itemInfo.m_sState = A2T("小于低低限");
					itemInfo.m_bStateOk = false;
					itemInfo.m_sRemark = A2T("低低限%1%2").arg(pCamerResult->m_sDataThreadHoldLL).arg(itemInfo.m_sUnit);
				}
				else if (-1 == pCamerResult->m_nState)
				{
					itemInfo.m_sState = A2T("小于低限");
					itemInfo.m_bStateOk = false;
					itemInfo.m_sRemark = A2T("低限%1%2").arg(pCamerResult->m_sDataThreadHoldL).arg(itemInfo.m_sUnit);
				}
				else if (0 == pCamerResult->m_nState)
				{
					itemInfo.m_sState = A2T("正常");
					itemInfo.m_bStateOk = true;
					//正常显示高限
					itemInfo.m_sRemark = A2T("高限%1%2").arg(pCamerResult->m_sDataThreadHoldH).arg(itemInfo.m_sUnit);
				}
				else if (1 == pCamerResult->m_nState)
				{
					itemInfo.m_sState = A2T("超高限");
					itemInfo.m_bStateOk = false;
					itemInfo.m_sRemark = A2T("高限%1%2").arg(pCamerResult->m_sDataThreadHoldH).arg(itemInfo.m_sUnit);
				}
				else if (2 == pCamerResult->m_nState)
				{
					itemInfo.m_sState = A2T("超高高限");
					itemInfo.m_bStateOk = false;
					itemInfo.m_sRemark = A2T("高高限%1%2").arg(pCamerResult->m_sDataThreadHoldHH).arg(itemInfo.m_sUnit);
				}
				else if (-10 == pCamerResult->m_nState)
				{
					itemInfo.m_sState = A2T("未执行");
					itemInfo.m_bStateOk = false;
					itemInfo.m_sRemark = A2T("未执行");
				}

			}

			mapFormInspectionPointInfo[sPointGuid].m_vecInspecItemsInfo.push_back(itemInfo);

		}
		else if (pTaskExecInfo->m_vecPolItemCom[i]->m_ItemResult->m_nDevType == 0)//本体传感器
		{
			CItemResultSensor *pSensorResult = (CItemResultSensor *)pTaskExecInfo->m_vecPolItemCom[i]->m_ItemResult;

			//基础数据
			CPdfOutInspecItemInfoAll itemInfo;
			itemInfo.m_sItemName = pSensorResult->m_sItemName;//新增巡检项名称
			itemInfo.eItemType = static_cast<EDevTypeCode>(pSensorResult->m_nDevTypeCode);
			itemInfo.m_doMeasurementVal = pSensorResult->m_dValue;//测量数值


			//特殊数据 单位不同
			if (enPM25 == pSensorResult->m_nDevTypeCode)
			{
				itemInfo.m_sUnit = A2T("ug/m3");
			}
			else if (enPM10 == pSensorResult->m_nDevTypeCode)
			{
				itemInfo.m_sUnit = A2T("ug/m3");
			}
			else if (enTemp == pSensorResult->m_nDevTypeCode)
			{
				itemInfo.m_sUnit = A2T("℃");
			}
			else if (enGas == pSensorResult->m_nDevTypeCode)
			{
				itemInfo.m_sUnit = A2T("ppm");
			}
			else if (enCO == pSensorResult->m_nDevTypeCode)
			{
				itemInfo.m_sUnit = A2T("ppm");
			}
			else if (enHum == pSensorResult->m_nDevTypeCode)
			{
				itemInfo.m_sUnit = A2T("%RH");

			}

			if (-2 == pSensorResult->m_nState)
			{
				itemInfo.m_sState = A2T("小于低低限");
				itemInfo.m_bStateOk = false;
				itemInfo.m_sRemark = A2T("低低限%1%2").arg(pSensorResult->m_sDataThreadHoldLL).arg(itemInfo.m_sUnit);
			}
			else if (-1 == pSensorResult->m_nState)
			{
				itemInfo.m_sState = A2T("小于低限");
				itemInfo.m_bStateOk = false;
				itemInfo.m_sRemark = A2T("低限%1%2").arg(pSensorResult->m_sDataThreadHoldL).arg(itemInfo.m_sUnit);
			}
			else if (0 == pSensorResult->m_nState)
			{
				itemInfo.m_sState = A2T("正常");
				itemInfo.m_bStateOk = true;
				//正常显示高限
				itemInfo.m_sRemark = A2T("高限%1%2").arg(pSensorResult->m_sDataThreadHoldH).arg(itemInfo.m_sUnit);
			}
			else if (1 == pSensorResult->m_nState)
			{
				itemInfo.m_sState = A2T("超高限");
				itemInfo.m_bStateOk = false;
				itemInfo.m_sRemark = A2T("高限%1%2").arg(pSensorResult->m_sDataThreadHoldH).arg(itemInfo.m_sUnit);
			}
			else if (2 == pSensorResult->m_nState)
			{
				itemInfo.m_sState = A2T("超高高限");
				itemInfo.m_bStateOk = false;
				itemInfo.m_sRemark = A2T("高高限%1%2").arg(pSensorResult->m_sDataThreadHoldHH).arg(itemInfo.m_sUnit);
			}
			else if (-10 == pSensorResult->m_nState)
			{
				itemInfo.m_sState = A2T("未执行");
				itemInfo.m_bStateOk = false;
				itemInfo.m_sRemark = A2T("未执行");;
			}

			mapFormInspectionPointInfo[sPointGuid].m_vecInspecItemsInfo.push_back(itemInfo);

		}

	}

	//巡检点数量"7个"
	dataInfo.robDataInfo.m_sInspPointCount = A2T("%1个").arg(mapFormInspectionPointInfo.size());
	//巡检项正常数量 "28项"
	dataInfo.robDataInfo.m_sInspItemNorCnt = A2T("%1项").arg(QString::number(pTaskExecInfo->m_nExecItemCount - pTaskExecInfo->m_nAlarmItemCount + nCotNormalNUmber));
	//巡检项异常数量 "2项"
	dataInfo.robDataInfo.m_sInspItemAbnorCnt = A2T("%1项").arg(QString::number(pTaskExecInfo->m_nAlarmItemCount + nCotAlmNumber));
	dataInfo.robDataInfo.m_nInspItemAbnorCnt = pTaskExecInfo->m_nAlarmItemCount + nCotAlmNumber;
	//巡检项数量改成:正常+异常
	dataInfo.robDataInfo.m_sInspItemCount = A2T("%1项").arg(QString::number((pTaskExecInfo->m_nExecItemCount - pTaskExecInfo->m_nAlarmItemCount + nCotNormalNUmber) + (pTaskExecInfo->m_nAlarmItemCount + nCotAlmNumber)));


	//新增异常项简明列表(异常项简要信息列表,有几项，增加几行)
	for (QMap<QString, CFormInspectionPointInfo>::iterator i = mapFormInspectionPointInfo.begin(); i != mapFormInspectionPointInfo.end(); i++)//遍历巡检点信息
	{
		//遍历这个点里面的巡检项
		for (int j = 0; j < i.value().m_vecInspecItemsInfo.size(); j++)
		{
			if (i.value().m_vecInspecItemsInfo[j].m_bStateOk == false)
			{
				QString sAbnormalBriefTemp = A2T("%1%2").arg(i.value().m_vecInspecItemsInfo[j].m_sItemName).arg(i.value().m_vecInspecItemsInfo[j].m_sState);
				dataInfo.robDataInfo.m_vecAbnorBriefList.push_back(sAbnormalBriefTemp);//把备注信息作为异常项简要信息
			}
		}
	}

	//异常项简明列表 需要加上统计连续检测的
	{
		//连续红外
		{
			QMap<int, QVector<CSingleCotDetInfo>> mapCotAppointIrInfo;//连续红外结果数组
			getCotAppointMapData(mapCotAppointIrInfo, dataInfo.robDataInfo.m_VecCotDetInfo, enIR);

			//遍历红外报警列表，往后继续绘制
			for (QMap<int, QVector<CSingleCotDetInfo>>::iterator j = mapCotAppointIrInfo.begin(); j != mapCotAppointIrInfo.end(); j++)
			{
				QVector<CSingleCotDetInfo> vecData = j.value();

				for (int nAlmIndex = 0; nAlmIndex < vecData.size(); nAlmIndex++)
				{
					if (vecData[nAlmIndex].m_nAlmState != 0)//只统计报警的
					{
						QString sAbnormalBriefInfo = A2T("%1托辊温度%2").arg(vecData[nAlmIndex].m_sRollerDesc).arg(vecData[nAlmIndex].m_strAlmDesc);
						dataInfo.robDataInfo.m_vecAbnorBriefList.push_back(sAbnormalBriefInfo);
					}

				}
			}
		}
		//连续噪声
		{
			QMap<int, QVector<CSingleCotDetInfo>> mapCotAppointVoiceInfo;//连续声音结果数组
			getCotAppointMapData(mapCotAppointVoiceInfo, dataInfo.robDataInfo.m_VecCotDetInfo, enVoice);

			//遍历声音报警列表
			for (QMap<int, QVector<CSingleCotDetInfo>>::iterator j = mapCotAppointVoiceInfo.begin(); j != mapCotAppointVoiceInfo.end(); j++)
			{
				QVector<CSingleCotDetInfo> vecData = j.value();

				for (int nAlmIndex = 0; nAlmIndex < vecData.size(); nAlmIndex++)
				{
					if (vecData[nAlmIndex].m_nAlmState != 0)//只统计报警的
					{
						QString sAbnormalBriefInfo = A2T("%1托辊噪声%2").arg(vecData[nAlmIndex].m_sRollerDesc).arg(vecData[nAlmIndex].m_strAlmDesc);
						dataInfo.robDataInfo.m_vecAbnorBriefList.push_back(sAbnormalBriefInfo);
					}

				}
			}
		}

	}

	//合格率计算
	double dPassPercent = (double)(pTaskExecInfo->m_nExecItemCount - pTaskExecInfo->m_nAlarmItemCount + nCotNormalNUmber) / (double)(pTaskExecInfo->m_nItemCount + nCotNormalNUmber + nCotAlmNumber);
	dPassPercent *= 100;
	int nPassPercent = (int)dPassPercent;
	dataInfo.robDataInfo.m_sPercentOfPass = A2T("%1%").arg(QString::number(nPassPercent));


	
	//当前系统时间
	QDateTime dtCurTime = QDateTime::currentDateTime();
	QString sCurrTime = dtCurTime.toString("yyyyMMddhhmmss");

	//创建文件夹
	QString sFolderTemp = sPdfFolderPath + "Result/" + dataInfo.robDataInfo.m_sRobotName + "/" + QDateTime::currentDateTime().toString("yyyyMM") + "/";//文件夹+机器人名称组合+年月

	QDir folder(sFolderTemp);// 创建QDir对象
	if (!folder.exists())
	{
		// 文件夹不存在，则创建
		if (folder.mkpath("."))
		{
		}
		else
		{
		}
	}
	else
	{
	}
	//输出路径
	QString sOutPath = sFolderTemp + sCurrTime + A2T("任务报告.pdf");
	pTaskExecInfo->m_sPdfPath = sOutPath;//本地路径

	QString sPathTemp = sOutPath;
	QString sPdfPathUrl = sHttpPrefix + sPathTemp.remove(sPdfFolderPath);
	QString sRobPdfPathUrl = sPdfPathUrl.replace("#", "%23");//URL路径
	pTaskExecInfo->m_sPdfPathUrl = sRobPdfPathUrl;

	dataInfo.robDataInfo.m_sOutputPdfFolder = sOutPath;
	dataInfo.robDataInfo.m_sRobPdfPathUrl = sRobPdfPathUrl;

	//最后将mapFormInspectionPointInfo按照巡检点的位置排序
	QVector<CFormInspectionPointInfo> vecPointInfo = mapFormInspectionPointInfo.values().toVector();
	qSort(vecPointInfo.begin(), vecPointInfo.end(), slotReport);
	dataInfo.robDataInfo.m_vecFormInspPointInfo.append(vecPointInfo);

	return true;
}

//组包纠偏数据
bool CPdfRptDataPkg::pkgRectifyPdfRptData(QDateTime dtSearchStartTime, QDateTime dtSearchEndTime, QString sBeltName, QString sPdfFolderPath, QString sHttpPrefix, CAllPdfRptDataInfo &dataInfo, QString &sErrMsg)
{
	dataInfo.rectifyDataInfo.m_sBeltName = sBeltName;//皮带名称

	//纠偏
	QDateTime dtCurTime = QDateTime::currentDateTime();//当前系统时间
	QString sCurrTime = dtCurTime.toString("yyyyMMddhhmmss");
	//创建文件夹
	QString sFolderTemp = sPdfFolderPath + "Result/" + "Rectify" + "/" + QDateTime::currentDateTime().toString("yyyyMM") + "/";//文件夹+Rectify+年月
	QDir folder(sFolderTemp);// 创建QDir对象
	if (!folder.exists())
	{
		// 文件夹不存在，则创建
		if (folder.mkpath("."))
		{
		}
		else
		{
		}
	}
	else
	{
	}
	//输出路径
	QString sOutPath = sFolderTemp + sCurrTime + A2T("独立纠偏报告.pdf");
	dataInfo.rectifyDataInfo.m_sOutputPdfFolder = sOutPath;
	

	QString sMsgRectify = "";
	QVector<QSqlRecord> vecRecordRectify;
	//CSqlOperAI::instance().selectNewTbRecRetInfo(vecRecordRectify, dtSearchStartTime.toString("yyyy-MM-dd hh:mm:ss"), dtSearchEndTime.toString("yyyy-MM-dd hh:mm:ss"), sMsgRectify, sBeltName);
	//dataInfo.rectifyDataInfo.m_nAlmCount = vecRecordRectify.size();
	dataInfo.rectifyDataInfo.m_sComment = A2T("空");
	dataInfo.rectifyDataInfo.m_sDetTime = dtSearchEndTime.toString("yyyy-MM-dd");
	dataInfo.rectifyDataInfo.m_sDetStartTime = dtSearchStartTime.toString("hh:mm:ss");
	dataInfo.rectifyDataInfo.m_sDetEndTime = dtSearchEndTime.toString("hh:mm:ss");
	for (int i = 0; i < vecRecordRectify.size(); i++)
	{
		QDateTime dtAlmNow = vecRecordRectify[i].value("INSERT_TIME").toDateTime();


		if (1 == vecRecordRectify[i].value("ALARM_TYPE").toInt())//报警才触发筛选
		{
			//需要根据配置的筛选时间筛选,比如60分钟之内只能有一条报警
			if (0 == i)//第一个报警是需要的
			{
				m_dtPrevRecAlm = dtAlmNow;
				dataInfo.rectifyDataInfo.m_nAlmCount += 1;
			}
			else//往后的报警进行比较
			{
				// 计算时间差（秒）
				int nSecDif = dtAlmNow.secsTo(m_dtPrevRecAlm);
				// 获取绝对值并转换为分钟
				int nMinutesDif = qAbs(nSecDif) / 60;

				if (nMinutesDif < CPublicData::instance().m_nFilterRecMinute)//指定分钟(比如60分钟)之内
				{
					continue;//本次报警直接过滤
				}
				else//超过时间，可以取新的报警了
				{
					m_dtPrevRecAlm = dtAlmNow;
					dataInfo.rectifyDataInfo.m_nAlmCount += 1;
				}

			}
		}
		
		CPdfRecSglAlmInfo pdfAlmInfo;
		pdfAlmInfo.m_sPictureUrl = vecRecordRectify[i].value("HTTP_PIC_URL").toString();
		pdfAlmInfo.m_sBeltName = vecRecordRectify[i].value("BELT_NAME").toString();
		pdfAlmInfo.m_sRecPointName = vecRecordRectify[i].value("POINT_NAME").toString();
		pdfAlmInfo.m_sRecStartTime = vecRecordRectify[i].value("RECTIFY_START_TIME").toDateTime().toString("hh:mm:ss");
		pdfAlmInfo.m_sRecEndTime = vecRecordRectify[i].value("RECTIFY_END_TIME").toDateTime().toString("hh:mm:ss");
		pdfAlmInfo.m_nAlmType = vecRecordRectify[i].value("ALARM_TYPE").toInt();

		dataInfo.rectifyDataInfo.m_vecFormRecAlmInfo.push_back(pdfAlmInfo);
	}

	return true;
}

//组包撕裂数据
bool CPdfRptDataPkg::pkgTearPdfRptData(QDateTime dtSearchStartTime, QDateTime dtSearchEndTime, QString sBeltName, QString sPdfFolderPath, QString sHttpPrefix, CAllPdfRptDataInfo &dataInfo, QString &sErrMsg)
{
	dataInfo.tearDataInfo.m_sBeltName = sBeltName;//皮带名称

	//撕裂
	QDateTime dtCurTime = QDateTime::currentDateTime();//当前系统时间
	QString sCurrTime = dtCurTime.toString("yyyyMMddhhmmss");
	//创建文件夹
	QString sFolderTemp = sPdfFolderPath + "Result/" + "Tear" + "/" + QDateTime::currentDateTime().toString("yyyyMM") + "/";//文件夹+Tear+年月
	QDir folder(sFolderTemp);// 创建QDir对象
	if (!folder.exists())
	{
		// 文件夹不存在，则创建
		if (folder.mkpath("."))
		{
		}
		else
		{
		}
	}
	else
	{
	}
	//输出路径
	QString sOutPath = sFolderTemp + sCurrTime + A2T("独立撕裂报告.pdf");
	dataInfo.tearDataInfo.m_sOutputPdfFolder = sOutPath;

	QString sMsgTear = "";
	QVector<QSqlRecord> vecRecordTear;
	//CSqlOperAI::instance().selectTearResultInfo(vecRecordTear, dtSearchStartTime.toString("yyyy-MM-dd hh:mm:ss"), dtSearchEndTime.toString("yyyy-MM-dd hh:mm:ss"), sMsgTear, sBeltName);

	//dataInfo.tearDataInfo.m_nAlmCount = vecRecordTear.size();
	dataInfo.tearDataInfo.m_sComment = A2T("空");
	dataInfo.tearDataInfo.m_sDetTime = dtSearchEndTime.toString("yyyy-MM-dd");
	dataInfo.tearDataInfo.m_sDetStartTime = dtSearchStartTime.toString("hh:mm:ss");
	dataInfo.tearDataInfo.m_sDetEndTime = dtSearchEndTime.toString("hh:mm:ss");
	for (int i = 0; i < vecRecordTear.size(); i++)
	{

		QDateTime dtAlmNow = vecRecordTear[i].value("INSERT_TIME").toDateTime();


		if (1 == vecRecordTear[i].value("ALARM_TYPE").toInt())//报警才触发筛选
		{
			//需要根据配置的筛选时间筛选,比如60分钟之内只能有一条报警
			if (0 == i)//第一个报警是需要的
			{
				m_dtPrevTearAlm = dtAlmNow;
				dataInfo.tearDataInfo.m_nAlmCount += 1;
			}
			else//往后的报警进行比较
			{
				// 计算时间差（秒）
				int nSecDif = dtAlmNow.secsTo(m_dtPrevTearAlm);
				// 获取绝对值并转换为分钟
				int nMinutesDif = qAbs(nSecDif) / 60;

				if (nMinutesDif < CPublicData::instance().m_nFilterTearMinute)//指定分钟(比如60分钟)之内
				{
					continue;//本次报警直接过滤
				}
				else//超过时间，可以取新的报警了
				{
					m_dtPrevTearAlm = dtAlmNow;
					dataInfo.tearDataInfo.m_nAlmCount += 1;
				}

			}
		}
		

		CPdfTearSglAlmInfo pdfAlmInfo;
		pdfAlmInfo.m_sPictureUrl = vecRecordTear[i].value("HTTP_PIC_URL").toString();
		//pdfAlmInfo.m_sBeltName = vecRecordTear[i].value("BELT_NAME").toString();
		pdfAlmInfo.m_sBeltName = vecRecordTear[i].value("TEAR_POINT_NAME").toString();//先按照撕裂点名称来
		pdfAlmInfo.m_sTearPointName = vecRecordTear[i].value("TEAR_POINT_NAME").toString();
		pdfAlmInfo.m_sTearStartTime = vecRecordTear[i].value("TEAR_START_TIME").toDateTime().toString("hh:mm:ss");
		pdfAlmInfo.m_sTearEndTime = vecRecordTear[i].value("TEAR_END_TIME").toDateTime().toString("hh:mm:ss");
		pdfAlmInfo.m_nAlmType = vecRecordTear[i].value("ALARM_TYPE").toInt();

		dataInfo.tearDataInfo.m_vecFormTearAlmInfo.push_back(pdfAlmInfo);
	}

	return true;
}

//组包其他AI检测数据
bool CPdfRptDataPkg::pkgRestAiPdfRptData(QDateTime dtSearchStartTime, QDateTime dtSearchEndTime, QString sBeltName, QString sPdfFolderPath, QString sHttpPrefix, CAllPdfRptDataInfo &dataInfo, QString &sErrMsg)
{
	//dataInfo.extraAiDataInfo.m_sBeltName = sBeltName;//皮带名称

	////其他AI检测
	//QDateTime dtCurTime = QDateTime::currentDateTime();//当前系统时间
	//QString sCurrTime = dtCurTime.toString("yyyyMMddhhmmss");
	////创建文件夹
	//QString sFolderTemp = sPdfFolderPath + "Result/" + "RestAi" + "/" + QDateTime::currentDateTime().toString("yyyyMM") + "/";//文件夹+RestAi+年月
	//QDir folder(sFolderTemp);// 创建QDir对象
	//if (!folder.exists())
	//{
	//	// 文件夹不存在，则创建
	//	if (folder.mkpath("."))
	//	{
	//	}
	//	else
	//	{
	//	}
	//}
	//else
	//{
	//}
	////输出路径
	//QString sOutPath = sFolderTemp + sCurrTime + A2T("独立其他AI检测报告.pdf");
	//dataInfo.extraAiDataInfo.m_sOutputPdfFolder = sOutPath;

	////去查询AI表
	//QVector<SAlarmInfoAi> vecAlarmInfoAi;
	//QString sCamerName = "";
	//vecAlarmInfoAi = CSqlOperAI::instance().getAlarmInfo(dtSearchStartTime.toString("yyyy-MM-dd hh:mm:ss"), dtSearchEndTime.toString("yyyy-MM-dd hh:mm:ss"), sCamerName, sErrMsg, sBeltName);
	//dataInfo.extraAiDataInfo.m_sDetTime = dtSearchEndTime.toString("yyyy-MM-dd");
	////dataInfo.extraAiDataInfo.m_nAlmCount = vecAlarmInfoAi.size();
	//dataInfo.extraAiDataInfo.m_sComment = A2T("空");
	//dataInfo.extraAiDataInfo.m_sDetStartTime = dtSearchStartTime.toString("hh:mm:ss");
	//dataInfo.extraAiDataInfo.m_sDetEndTime = dtSearchEndTime.toString("hh:mm:ss");
	//for (int i = 0; i < vecAlarmInfoAi.size(); i++)
	//{
	//	QDateTime dtAlmNow = QDateTime::fromString(vecAlarmInfoAi[i].sTime, "yyyy-MM-dd hh:mm:ss");
	//	//需要根据配置的筛选时间筛选,比如60分钟之内只能有一条报警
	//	if (0 == i)//第一个报警是需要的
	//	{
	//		m_dtPrevRestAiAlm = dtAlmNow;
	//		dataInfo.extraAiDataInfo.m_nAlmCount += 1;
	//	}
	//	else//往后的报警进行比较
	//	{
	//		// 计算时间差（秒）
	//		int nSecDif = dtAlmNow.secsTo(m_dtPrevRestAiAlm);
	//		// 获取绝对值并转换为分钟
	//		int nMinutesDif = qAbs(nSecDif) / 60;

	//		if (nMinutesDif < CPublicData::instance().m_nFilterRestAiMinute)//指定分钟(比如60分钟)之内
	//		{
	//			continue;//本次报警直接过滤
	//		}
	//		else//超过时间，可以取新的报警了
	//		{
	//			m_dtPrevRestAiAlm = dtAlmNow;
	//			dataInfo.extraAiDataInfo.m_nAlmCount += 1;
	//		}

	//	}

	//	CPdfExtraAiAlmInfo almInfo;

	//	almInfo.m_sHttpPictureUrl = vecAlarmInfoAi[i].sAlarmPicPath;
	//	almInfo.m_sAlmDesc = A2T("%1%2").arg(vecAlarmInfoAi[i].sAlgName).arg(vecAlarmInfoAi[i].sCamerName);
	//	QDateTime dtAlm = QDateTime::fromString(vecAlarmInfoAi[i].sTime, "yyyy-MM-dd hh:mm:ss");
	//	almInfo.m_sAlmTime = dtAlm.toString("hh:mm:ss");
	//	almInfo.m_dImageWid = vecAlarmInfoAi[i].dImageWidth;
	//	almInfo.m_dImageHig = vecAlarmInfoAi[i].dImageHeight;
	//	for (int j = 0; j < vecAlarmInfoAi[i].vecPolygonAlarm.size(); j++)
	//	{
	//		CPdfAiPicPolygonArea AiPicPolygonArea;
	//		AiPicPolygonArea.bPolygonAlarm = vecAlarmInfoAi[i].vecPolygonAlarm[j].bPolygonAlarm;
	//		AiPicPolygonArea.dPolygonScore = vecAlarmInfoAi[i].vecPolygonAlarm[j].dPolygonScore;
	//		AiPicPolygonArea.pPoint = vecAlarmInfoAi[i].vecPolygonAlarm[j].pPoint;
	//		AiPicPolygonArea.dWidth = vecAlarmInfoAi[i].vecPolygonAlarm[j].dWidth;
	//		AiPicPolygonArea.dHeight = vecAlarmInfoAi[i].vecPolygonAlarm[j].dHeight;

	//		almInfo.vecPolygonArea.push_back(AiPicPolygonArea);
	//	}

	//	int nAiType = 0;//类型(0:传送带异物识别 1:传送带煤流量检测)
	//	switch (vecAlarmInfoAi[i].nTaskId)
	//	{
	//	case 109:
	//		nAiType = enConvBeltForeObjDet;
	//		break;
	//	case 132:
	//		nAiType = enConvBeltMassFlowDet;
	//		break;
	//	default:
	//		nAiType = enUnknowAriType;
	//		break;
	//	}
	//	if (dataInfo.extraAiDataInfo.m_mapExtraAiInfo.contains(nAiType))
	//	{
	//		// 获取对应的 QVector
	//		QVector<CPdfExtraAiAlmInfo> &vecAlmData = dataInfo.extraAiDataInfo.m_mapExtraAiInfo[nAiType];
	//		vecAlmData.append(almInfo);
	//	}
	//	else
	//	{
	//		// 插入对应的 QVector
	//		QVector<CPdfExtraAiAlmInfo> vecAlmData;
	//		vecAlmData.push_back(almInfo);
	//		dataInfo.extraAiDataInfo.m_mapExtraAiInfo.insert(nAiType, vecAlmData);

	//	}
	//}

	return true;
}

//组包声振温数据
bool CPdfRptDataPkg::pkgSesePdfRptData(QDateTime dtSearchStartTime, QDateTime dtSearchEndTime, QString sBeltName, QString sPdfFolderPath, QString sHttpPrefix, CAllPdfRptDataInfo &dataInfo, QString &sErrMsg)
{
	dataInfo.seseDataInfo.m_sBeltName = sBeltName;//皮带名称

	//声振温
	QDateTime dtCurTime = QDateTime::currentDateTime();//当前系统时间
	QString sCurrTime = dtCurTime.toString("yyyyMMddhhmmss");
	//创建文件夹
	QString sFolderTemp = sPdfFolderPath + "Result/" + "Sese" + "/" + QDateTime::currentDateTime().toString("yyyyMM") + "/";//文件夹+Tear+年月
	QDir folder(sFolderTemp);// 创建QDir对象
	if (!folder.exists())
	{
		// 文件夹不存在，则创建
		if (folder.mkpath("."))
		{
		}
		else
		{
		}
	}
	else
	{
	}
	//输出路径
	QString sOutPath = sFolderTemp + sCurrTime + A2T("独立声振温报告.pdf");
	dataInfo.seseDataInfo.m_sOutputPdfFolder = sOutPath;

	QString sMsgSese = "";
	QVector<QSqlRecord> vecRecordSese;
	//CSqlOperAI::instance().selSeseResultInfo(vecRecordSese, dtSearchStartTime.toString("yyyy-MM-dd hh:mm:ss"), dtSearchEndTime.toString("yyyy-MM-dd hh:mm:ss"), sBeltName, sMsgSese);

	//dataInfo.seseDataInfo.m_nAlmCount = vecRecordSese.size();
	dataInfo.seseDataInfo.m_sComment = A2T("空");
	dataInfo.seseDataInfo.m_sDetTime = dtSearchEndTime.toString("yyyy-MM-dd");
	dataInfo.seseDataInfo.m_sDetStartTime = dtSearchStartTime.toString("hh:mm:ss");
	dataInfo.seseDataInfo.m_sDetEndTime = dtSearchEndTime.toString("hh:mm:ss");
	for (int i = 0; i < vecRecordSese.size(); i++)
	{
		QDateTime dtAlmNow = vecRecordSese[i].value("ALARM_TIME").toDateTime();
		//需要根据配置的筛选时间筛选,比如60分钟之内只能有一条报警
		if (0 == i)//第一个报警是需要的
		{
			m_dtPrevSeseAlm = dtAlmNow;
			dataInfo.seseDataInfo.m_nAlmCount += 1;
		}
		else//往后的报警进行比较
		{
			// 计算时间差（秒）
			int nSecDif = dtAlmNow.secsTo(m_dtPrevSeseAlm);
			// 获取绝对值并转换为分钟
			int nMinutesDif = qAbs(nSecDif) / 60;

			if (nMinutesDif < CPublicData::instance().m_nFilterSeseMinute)//指定分钟(比如60分钟)之内
			{
				continue;//本次报警直接过滤
			}
			else//超过时间，可以取新的报警了
			{
				m_dtPrevSeseAlm = dtAlmNow;
				dataInfo.seseDataInfo.m_nAlmCount += 1;
			}

		}

		CPdfSeSeSglAlmInfo pdfAlmInfo;
		pdfAlmInfo.m_sDevName = vecRecordSese[i].value("DEV_NAME").toString();
		pdfAlmInfo.m_nChannelNo = vecRecordSese[i].value("CHANNEL_NO").toInt();
		pdfAlmInfo.sAlmTime = vecRecordSese[i].value("ALARM_TIME").toDateTime().toString("hh:mm:ss");
		pdfAlmInfo.sAccDirect = vecRecordSese[i].value("ACC_DIRECT").toString();
		pdfAlmInfo.nTempAlm = vecRecordSese[i].value("TEMP_ALARM").toInt();
		pdfAlmInfo.nVibrationAlm = vecRecordSese[i].value("VIBRATION_ALARM").toInt();
		pdfAlmInfo.nVoiceAlm = vecRecordSese[i].value("VOICE_ALARM").toInt();
		pdfAlmInfo.m_dTempVal = vecRecordSese[i].value("TEMP_VALUE").toDouble();
		pdfAlmInfo.m_sBeltName = vecRecordSese[i].value("BELT_NAME").toString();
		pdfAlmInfo.m_dRms = vecRecordSese[i].value("RMS").toDouble();
		pdfAlmInfo.m_sChannelName = vecRecordSese[i].value("CHANNEL_NAME").toString();

		dataInfo.seseDataInfo.m_vecFormSeSeAlmInfo.push_back(pdfAlmInfo);
	}

	return true;

}

//组包球机数据
bool CPdfRptDataPkg::pkgBaCamPdfRptData(QDateTime dtSearchStartTime, QDateTime dtSearchEndTime, QString sBeltName, QString sBaCamSceneGuid, QString sPdfFolderPath, QString sHttpPrefix, CAllPdfRptDataInfo &dataInfo, QString &sErrMsg)
{
	dataInfo.bacamDataInfo.m_sBeltName = sBeltName;//皮带名称

	//球机
	QDateTime dtCurTime = QDateTime::currentDateTime();//当前系统时间
	QString sCurrTime = dtCurTime.toString("yyyyMMddhhmmss");
	//创建文件夹
	QString sFolderTemp = sPdfFolderPath + "Result/" + "BaCam" + "/" + QDateTime::currentDateTime().toString("yyyyMM") + "/";//文件夹+Tear+年月
	QDir folder(sFolderTemp);// 创建QDir对象
	if (!folder.exists())
	{
		// 文件夹不存在，则创建
		if (folder.mkpath("."))
		{
		}
		else
		{
		}
	}
	else
	{
	}
	//输出路径
	QString sOutPath = sFolderTemp + sCurrTime + A2T("独立球机报告.pdf");
	dataInfo.bacamDataInfo.m_sOutputPdfFolder = sOutPath;

	QVector<QSqlRecord> vecRecordbacam;
	//CSqlOperRob::instance().selBaCamResultInfo(vecRecordbacam, dtSearchStartTime.toString("yyyy-MM-dd hh:mm:ss"), dtSearchEndTime.toString("yyyy-MM-dd hh:mm:ss"), sBaCamSceneGuid, sErrMsg);

	//dataInfo.bacamDataInfo.m_nAlmCount = vecRecordbacam.size();
	dataInfo.bacamDataInfo.m_sComment = A2T("空");
	dataInfo.bacamDataInfo.m_sDetTime = dtSearchEndTime.toString("yyyy-MM-dd");
	dataInfo.bacamDataInfo.m_sDetStartTime = dtSearchStartTime.toString("hh:mm:ss");
	dataInfo.bacamDataInfo.m_sDetEndTime = dtSearchEndTime.toString("hh:mm:ss");
	for (int i = 0; i < vecRecordbacam.size(); i++)
	{

		QDateTime dtAlmNow = vecRecordbacam[i].value("START_TIME").toDateTime();

		if (vecRecordbacam[i].value("ALARM_LEVEL").toInt() > 0)//报警才触发筛选
		{
			//需要根据配置的筛选时间筛选,比如60分钟之内只能有一条报警
			if (0 == i)//第一个报警是需要的
			{
				m_dtPrevBaCamAlm = dtAlmNow;
				dataInfo.bacamDataInfo.m_nAlmCount += 1;
			}
			else//往后的报警进行比较
			{
				// 计算时间差（秒）
				int nSecDif = dtAlmNow.secsTo(m_dtPrevBaCamAlm);
				// 获取绝对值并转换为分钟
				int nMinutesDif = qAbs(nSecDif) / 60;

				if (nMinutesDif < CPublicData::instance().m_nFilterBaCamMinute)//指定分钟(比如60分钟)之内
				{
					continue;//本次报警直接过滤
				}
				else//超过时间，可以取新的报警了
				{
					m_dtPrevBaCamAlm = dtAlmNow;
					dataInfo.bacamDataInfo.m_nAlmCount += 1;
				}

			}
		}
		

		CPdfBaCamSglAlmInfo pdfAlmInfo;
		pdfAlmInfo.m_sAlmTime = vecRecordbacam[i].value("START_TIME").toDateTime().toString("hh:mm:ss");
		pdfAlmInfo.m_sAlmDesc = vecRecordbacam[i].value("IR_RESULT_DATA_STR").toString();
		pdfAlmInfo.m_sLocPicPath = vecRecordbacam[i].value("IR_URL").toString();
		
		pdfAlmInfo.m_sBaCamName = vecRecordbacam[i].value("POINT_GUID").toString();//球机名称 用POINT_GUID字段获取
		pdfAlmInfo.m_sBaCamItemName = vecRecordbacam[i].value("ITEM_GUID").toString();//球机检测项名称 用ITEM_GUID字段获取
		int nAlmLev = vecRecordbacam[i].value("ALARM_LEVEL").toInt();
		pdfAlmInfo.m_nAlmType = nAlmLev == 0 ? 0 : 1;//报警等级(0:未报警 1:报警) PS:新增本字段，用于区分存储非报警信息
		pdfAlmInfo.m_dMaxTemp = vecRecordbacam[i].value("TEMP_MAX").toDouble();//最高温度
		pdfAlmInfo.m_dMinTemp = vecRecordbacam[i].value("TEMP_MIN").toDouble();//最低温度
		pdfAlmInfo.m_dAvgTemp = vecRecordbacam[i].value("TEMP_AGV").toDouble();//平均温度
		pdfAlmInfo.m_dDataThresholdH = vecRecordbacam[i].value("DATA_THRESHOLD_H").toDouble();//高报阈值

		dataInfo.bacamDataInfo.m_vecFormBaCamAlmInfo.push_back(pdfAlmInfo);
	}

	return true;

}

//获取组包查询参数(机器人任务结束，查找前后两次任务时间、皮带名称、球机场景Guid)
void CPdfRptDataPkg::getPkgSearchParam(QString sRobSceneGuid, QDateTime &dtLastTaskEndTime, QDateTime &dtNowTaskEndTime, QString &sBeltNameDeal, QString &sBeltNameOri, QString &sBaCamSceneGuid)
{
	QString sErrMsg = "";
	QString sLastTaskEndTime = "";//上一次任务结束时间
	QString sNowTaskEndTime = "";//本次任务结束时间
	//CSqlOperRob::instance().getTaskTimeInterval(sRobSceneGuid, sErrMsg, sLastTaskEndTime, sNowTaskEndTime);
	dtLastTaskEndTime = QDateTime::fromString(sLastTaskEndTime, "yyyy-MM-dd hh:mm:ss");
	dtNowTaskEndTime = QDateTime::fromString(sNowTaskEndTime, "yyyy-MM-dd hh:mm:ss");

	//获取皮带名称
	QString sBeltNameGet = getRobBelongBelt(sRobSceneGuid);
	sBeltNameOri = sBeltNameGet;//原始皮带名称


	//因为现场都是类似C102#皮带这种名称,这里的皮带名称需要按照#分割取#左边的
	if (sBeltNameGet.contains("#"))
	{
		QStringList slistName = sBeltNameGet.split("#");
		if (slistName.size() > 0)
		{
			sBeltNameDeal = slistName[0];
		}
	}
	else
	{
		sBeltNameDeal = sBeltNameGet;
	}

	//=====获取球机场景Guid=====
	sBaCamSceneGuid = getBaCamSceneGuid(sBeltNameOri);

}

//获取组包任务执行信息(数据库中查找数据)
void CPdfRptDataPkg::getPkgTaskExecInfo(QString sTaskExecGuid, CTaskExecInfo *pTaskExecInfo, QString &sRobName)
{
	if (pTaskExecInfo == nullptr)
	{
		return;
	}

	QString sSceneGuidNow = "";//场景Guid

	//===============查询数据库进行pTaskExecInfo组包================
	//查询数据库中prob_task_exec_records表该任务执行记录信息
	{
		QVector<QSqlRecord> vecDataInfo;
		QString sErrMsg = "";
		//CSqlOperRob::instance().selectTaskExecByGuid(sTaskExecGuid, vecDataInfo, sErrMsg);
		for (int i = 0; i < vecDataInfo.size(); i++)
		{
			if (0 == i)
			{
				pTaskExecInfo->m_sTaskExecGuid = vecDataInfo[i].value("GUID").toString();
				pTaskExecInfo->m_sTaskName = vecDataInfo[i].value("TASK_NAME").toString();
				pTaskExecInfo->m_sTemplateGuid = vecDataInfo[i].value("TEMPLATE_GUID").toString();
				pTaskExecInfo->m_sGuid = vecDataInfo[i].value("SCENE_GUID").toString();
				sSceneGuidNow = pTaskExecInfo->m_sGuid;
				pTaskExecInfo->m_nExecState = vecDataInfo[i].value("EXEC_STATUS").toInt();
				pTaskExecInfo->m_nItemCount = vecDataInfo[i].value("ITEM_COUNT").toInt();
				pTaskExecInfo->m_nExecItemCount = vecDataInfo[i].value("EXEC_ITEM_COUNT").toInt();
				pTaskExecInfo->m_nAlarmItemCount = vecDataInfo[i].value("ALARM_ITEM_COUNT").toInt();
				pTaskExecInfo->m_sStartTime = vecDataInfo[i].value("START_TIME").toDateTime().toString("yyyy-MM-dd hh:mm:ss");
				pTaskExecInfo->m_sEndTime = vecDataInfo[i].value("END_TIME").toDateTime().toString("yyyy-MM-dd hh:mm:ss");
				pTaskExecInfo->m_dStartPower = vecDataInfo[i].value("START_POWER").toDouble();
				pTaskExecInfo->m_dEndPower = vecDataInfo[i].value("END_POWER").toDouble();

				pTaskExecInfo->m_sTaskExecDes = vecDataInfo[i].value("TASK_EXEC_DSC").toString();
			}
			break;
		}
	}

	//===============查询机器人名称==================
	//CSqlOperPub::instance().selDevNameBySceneID(sSceneGuidNow, sRobName);
	

	//===============查询创建基础数据==================
	//创建巡检区域
	CPolArea *pPolArea = new CPolArea();
	QString sErrMsg = "";
	//CSqlOperRob::instance().selectPollAreaBySceneID(sSceneGuidNow, pPolArea, sErrMsg);

	//创建巡检点
	//CSqlOperRob::instance().selectPolPointBySceneID(sSceneGuidNow, pPolArea->m_mapPolPoint, sErrMsg);

	//创建云台巡检项
	//CSqlOperRob::instance().selectPloItemCamerBySceneID(sSceneGuidNow, pPolArea->m_mapPolPoint, sErrMsg);

	//创建传感器巡检项
	//CSqlOperRob::instance().selectPloItemSensorBySceneID(sSceneGuidNow, pPolArea->m_mapPolPoint, sErrMsg);
	
	//===============查询数据==================
	//查询数据库中prob_sensor_item_exec_records表本体巡检项信息
	//巡检项结果数组对象pTaskExecInfo->m_vecPolItemCom 里面是一个个SCPolItemCom(巡检项执行结果)
	//查找遍历传感器巡检项结果
	{
		QVector<QSqlRecord> vecRecord;
		QString sErrMsg = "";
		//CSqlOperRob::instance().selectSensorItemExecByTaskExecID(sSceneGuidNow, sTaskExecGuid, vecRecord, sErrMsg);
		for (int i = 0; i < vecRecord.size(); i++)
		{
			SCPolItemCom *pItemCom = new SCPolItemCom();//new巡检项执行结果

			pItemCom->m_bIsAction = true;//是否已执行
			pItemCom->m_bIsSave = true;//是否已经保存到数据库
			pItemCom->m_bIsShow = true;//是否已经在界面上显示

			QString sBelPointGuid = vecRecord[i].value("POINT_GUID").toString();//巡检点GUID
			QString sTemplateFixedID = vecRecord[i].value("TEMPLATE_GUID").toString();//模板GUID
			QString sBelItemGuid = vecRecord[i].value("ITEM_GUID").toString();//巡检项Guid
			//找到对应巡检点
			CPolPoint *pBelPoint = nullptr;
			if (pPolArea->m_mapPolPoint.contains(sBelPointGuid))
			{
				pBelPoint = pPolArea->m_mapPolPoint[sBelPointGuid];
			}
			if (pBelPoint == nullptr)
			{
				continue;
			}
			//找到对应模板
			//CTemplateInfo cTemplateInfo = CSqlOperRob::instance().selectTemplateInfo(sTemplateFixedID, sErrMsg);
			//找到对应巡检项
			CPolItem *pBelItem = nullptr;
			if (pBelPoint->m_mapPolItem.contains(sBelItemGuid))
			{
				pBelItem = pBelPoint->m_mapPolItem[sBelItemGuid];
			}
			if (pBelItem == nullptr)
			{
				continue;
			}

			pItemCom->m_pPolPoint = new CPolPoint();//巡检点 new新的
			pBelPoint->copyData(pItemCom->m_pPolPoint);//copy巡检点pBelPoint的数据

			//巡检结果
			{
				//本体巡检项
				CItemResultBase *pItemResult = new CItemResultSensor();
				pItemResult->m_sItemResultGuid = vecRecord[i].value("POINT_GUID").toString();
				pItemResult->m_sPolAreaGuid = pPolArea->m_sPolAreaGuid;
				pItemResult->m_sPointGuid = sBelPointGuid;
				pItemResult->m_sItemGuid = sBelItemGuid;
				pItemResult->m_sTaskGuid = createGuid();
				pItemResult->m_sTemplateGuid = sTemplateFixedID;
				pItemResult->m_sStartTime = vecRecord[i].value("START_TIME").toDateTime().toString("yyyy/MM/dd hh:mm:ss");//执行时间
				pItemResult->m_sTaskName = A2T("巡检任务");
				pItemResult->m_sPointName = pBelPoint->m_sPointName;
				pItemResult->m_sItemName = pBelItem->m_sItemName;
				pItemResult->m_sGuid = sSceneGuidNow;
				pItemResult->m_sDataThreadHoldHH = pBelItem->m_sDataThreadHoldHH;     //数字阈值--高高报警
				pItemResult->m_sDataThreadHoldLL = pBelItem->m_sDataThreadHoldLL;     //数字阈值--低低报警
				pItemResult->m_sDataThreadHoldH = pBelItem->m_sDataThreadHoldH;      //数字阈值--高报警
				pItemResult->m_sDataThreadHoldL = pBelItem->m_sDataThreadHoldL;      //数字阈值--低报警
				pItemResult->m_sTaskExecGuid = sTaskExecGuid;
				pItemResult->m_nDevType = pBelItem->m_nDevType;//设备类型枚举  0 本体(传感器)  1云台
				pItemResult->m_nCheckType = pBelItem->m_nCheckType;//数据上报类型 0.调用返回  1.持续任务主动上报
				pItemResult->m_nDevTypeCode = pBelItem->m_nDevTypeCode;
				pItemResult->m_nBelong = pBelItem->m_nBelong;
				pItemResult->m_dActionTime = vecRecord[i].value("START_TIME").toDateTime();
				pItemResult->m_nAlarmLevel = vecRecord[i].value("ALARM_LEVEL").toInt();
				if (0 == pItemResult->m_nAlarmLevel)
				{
					pItemResult->m_nState = 0;
				}
				else
				{
					pItemResult->m_nState = 1;
				}
				pItemResult->m_dValue = vecRecord[i].value("SENSOR_DATA").toDouble();
				pItemResult->m_sDataDesc = vecRecord[i].value("SENSOR_DATA_DESC").toString();
				pItemResult->m_dRealLocation = 0.5;
				pItemResult->m_nRollerNum = vecRecord[i].value("ROLLER_NO").toInt();
				pItemResult->m_sRollerDesc = vecRecord[i].value("ROLLER_CODE").toString();
				pItemResult->m_bIsShow = true;
				pItemCom->m_ItemResult = pItemResult;
			}
			pTaskExecInfo->m_vecPolItemCom.push_back(pItemCom);

			pItemCom->m_pPolItem = new CPolItemSensor();;//巡检项 new新的
			pBelItem->copyData(pItemCom->m_pPolItem);//copy巡检项pBelItem的数据

		}

	}
	
	//查找遍历云台巡检项结果
	{
		QVector<QSqlRecord> vecRecord;
		QString sErrMsg = "";
		//CSqlOperRob::instance().selectImageItemExecByTaskExecID(sSceneGuidNow, sTaskExecGuid, vecRecord, sErrMsg);//根据场景ID获取云台巡检项执行记录表
		//第一遍先排除掉连续检测结果,处理正常发检测巡检项结果
		for (int i = 0; i < vecRecord.size(); i++)
		{
			//是连续检测直接排除
			if (vecRecord[i].value("IS_COTDET").toInt() == 1)
			{
				continue;
			}

			int nItemTypeCodeNow = vecRecord[i].value("ITEM_TYPE_CODE").toInt();

			QString sBelPointGuid = vecRecord[i].value("POINT_GUID").toString();//巡检点GUID
			QString sTemplateFixedID = vecRecord[i].value("TEMPLATE_GUID").toString();//模板GUID
			QString sBelItemGuid = vecRecord[i].value("ITEM_GUID").toString();//巡检项Guid
			//找到对应巡检点
			CPolPoint *pBelPoint = nullptr;
			if (pPolArea->m_mapPolPoint.contains(sBelPointGuid))
			{
				pBelPoint = pPolArea->m_mapPolPoint[sBelPointGuid];
			}
			if (pBelPoint == nullptr)
			{
				continue;
			}

			//找到对应模板
			//CTemplateInfo cTemplateInfo = CSqlOperRob::instance().selectTemplateInfo(sTemplateFixedID, sErrMsg);
			//找到对应巡检项
			CPolItem *pBelItem = nullptr;
			if (pBelPoint->m_mapPolItem.contains(sBelItemGuid))
			{
				pBelItem = pBelPoint->m_mapPolItem[sBelItemGuid];
			}
			if (pBelItem == nullptr)
			{
				continue;
			}

			SCPolItemCom *pItemCom = new SCPolItemCom();//new巡检项执行结果

			pItemCom->m_bIsAction = true;//是否已执行
			pItemCom->m_bIsSave = true;//是否已经保存到数据库
			pItemCom->m_bIsShow = true;//是否已经在界面上显示

			pItemCom->m_pPolPoint = new CPolPoint();//巡检点 new新的
			pBelPoint->copyData(pItemCom->m_pPolPoint);//copy巡检点pBelPoint的数据

			//巡检结果
			{
				CItemResultBase *pItemResult = new CItemResultCamera();
				pItemResult->m_sItemResultGuid = vecRecord[i].value("POINT_GUID").toString();
				pItemResult->m_sPolAreaGuid = pPolArea->m_sPolAreaGuid;
				pItemResult->m_sPointGuid = sBelPointGuid;
				pItemResult->m_sItemGuid = sBelItemGuid;
				pItemResult->m_sTaskGuid = createGuid();
				pItemResult->m_sTemplateGuid = sTemplateFixedID;
				pItemResult->m_sStartTime = vecRecord[i].value("START_TIME").toDateTime().toString("yyyy/MM/dd hh:mm:ss");//执行时间
				pItemResult->m_sTaskName = A2T("巡检任务");
				pItemResult->m_sPointName = pBelPoint->m_sPointName;
				pItemResult->m_sItemName = pBelItem->m_sItemName;
				pItemResult->m_sGuid = sSceneGuidNow;
				pItemResult->m_sDataThreadHoldHH = pBelItem->m_sDataThreadHoldHH;     //数字阈值--高高报警
				pItemResult->m_sDataThreadHoldLL = pBelItem->m_sDataThreadHoldLL;     //数字阈值--低低报警
				pItemResult->m_sDataThreadHoldH = pBelItem->m_sDataThreadHoldH;      //数字阈值--高报警
				pItemResult->m_sDataThreadHoldL = pBelItem->m_sDataThreadHoldL;      //数字阈值--低报警
				pItemResult->m_sTaskExecGuid = sTaskExecGuid;
				pItemResult->m_nDevType = pBelItem->m_nDevType;//设备类型枚举  0 本体(传感器)  1云台
				pItemResult->m_nCheckType = pBelItem->m_nCheckType;//数据上报类型 0.调用返回  1.持续任务主动上报
				pItemResult->m_nDevTypeCode = pBelItem->m_nDevTypeCode;
				pItemResult->m_nBelong = vecRecord[i].value("BELONG").toInt();
				pItemResult->m_dActionTime = vecRecord[i].value("START_TIME").toDateTime();
				pItemResult->m_nAlarmLevel = vecRecord[i].value("ALARM_LEVEL").toInt();
				if (0 == pItemResult->m_nAlarmLevel)
				{
					pItemResult->m_nState = 0;
				}
				else
				{
					pItemResult->m_nState = 1;
				}
				//pItemResult->m_dValue = vecRecord[i].value("SENSOR_DATA").toDouble();
				//pItemResult->m_sDataDesc = vecRecord[i].value("SENSOR_DATA_DESC").toString();
				//pItemResult->m_dRealLocation = 0.5;
				pItemResult->m_nRollerNum = vecRecord[i].value("ROLLER_NO").toInt();
				pItemResult->m_sRollerDesc = vecRecord[i].value("ROLLER_CODE").toString();
				pItemResult->m_bIsShow = true;

				CItemResultCamera *pItemResultCam = (CItemResultCamera *)pItemResult;//相机结果
				pItemResultCam->m_sHttpUrl = vecRecord[i].value("RESULT_HTTP_URL").toString();
				pItemResultCam->m_sIRUrl = vecRecord[i].value("IR_URL").toString();
				pItemResultCam->m_sAlarmUrl = vecRecord[i].value("IR_URL").toString();


				if (nItemTypeCodeNow == enIR)//红外
				{
					pItemResultCam->m_dTempMax = vecRecord[i].value("TEMP_MAX").toDouble();
					pItemResultCam->m_dTempMin = vecRecord[i].value("TEMP_MIN").toDouble();
					pItemResultCam->m_dTempAverage = vecRecord[i].value("TEMP_AGV").toDouble();
				}
				else if (nItemTypeCodeNow == enVoice)//vecRecord[i].value("VOICE_DATA").toString()
				{
					pItemResultCam->m_dValue = vecRecord[i].value("VOICE_DATA").toDouble();
				}
				pItemCom->m_ItemResult = pItemResult;
			}

			pTaskExecInfo->m_vecPolItemCom.push_back(pItemCom);

			pItemCom->m_pPolItem = new CPolItemCamer();;//所属巡检项 new新的
			pBelItem->copyData(pItemCom->m_pPolItem);//copy巡检项的数据
		}

		//第二遍先排除掉普通检测结果，添加连续检测结果(每种连续检测先定义一个巡检项)
		SCPolItemCom *pItemComCotIrOne = nullptr;//连续红外结果
		SCPolItemCom *pItemComCotImageOne = nullptr;//连续图像结果
		SCPolItemCom *pItemComCotVoiceOne = nullptr;//连续声音结果
		int nIrOnce = 0;
		int nImageOnce = 0;
		int nVoiceOnce = 0;
		for (int i = 0; i < vecRecord.size(); i++)
		{
			//非连续检测直接PASS
			if (vecRecord[i].value("IS_COTDET").toInt() == 0)
			{
				continue;
			}

			int nItemTypeCodeNow = vecRecord[i].value("ITEM_TYPE_CODE").toInt();

			QString sBelPointGuid = vecRecord[i].value("POINT_GUID").toString();//巡检点GUID
			QString sTemplateFixedID = vecRecord[i].value("TEMPLATE_GUID").toString();//模板GUID
			QString sBelItemGuid = vecRecord[i].value("ITEM_GUID").toString();//巡检项Guid
			//找到对应巡检点
			CPolPoint *pBelPoint = nullptr;
			if (pPolArea->m_mapPolPoint.contains(sBelPointGuid))
			{
				pBelPoint = pPolArea->m_mapPolPoint[sBelPointGuid];
			}
			if (pBelPoint == nullptr)
			{
				continue;
			}
			//找到对应巡检项
			CPolItem *pBelItem = nullptr;
			if (pBelPoint->m_mapPolItem.contains(sBelItemGuid))
			{
				pBelItem = pBelPoint->m_mapPolItem[sBelItemGuid];
			}
			if (pBelItem == nullptr)
			{
				continue;
			}

			if (nItemTypeCodeNow == enIR && 0 == nIrOnce)
			{
				pItemComCotIrOne = new SCPolItemCom();
				pItemComCotIrOne->m_bIsAction = true;//是否已执行
				pItemComCotIrOne->m_bIsSave = true;//是否已经保存到数据库
				pItemComCotIrOne->m_bIsShow = true;//是否已经在界面上显示


				pItemComCotIrOne->m_pPolPoint = new CPolPoint();//所属巡检点 new新的
				pBelPoint->copyData(pItemComCotIrOne->m_pPolPoint);//copy巡检点pPolPoint1的数据
				//巡检结果
				{
					CItemResultBase *pItemResult = new CItemResultCamera();
					pItemResult->m_sItemResultGuid = vecRecord[i].value("POINT_GUID").toString();
					pItemResult->m_sPolAreaGuid = pPolArea->m_sPolAreaGuid;
					pItemResult->m_sPointGuid = sBelPointGuid;
					pItemResult->m_sItemGuid = sBelItemGuid;
					pItemResult->m_sTaskGuid = createGuid();
					pItemResult->m_sTemplateGuid = sTemplateFixedID;
					pItemResult->m_sStartTime = vecRecord[i].value("START_TIME").toDateTime().toString("yyyy/MM/dd hh:mm:ss");//执行时间
					pItemResult->m_sTaskName = A2T("巡检任务");
					pItemResult->m_sPointName = pBelPoint->m_sPointName;
					pItemResult->m_sItemName = pBelItem->m_sItemName;
					pItemResult->m_sGuid = sSceneGuidNow;
					pItemResult->m_sDataThreadHoldHH = pBelItem->m_sDataThreadHoldHH;     //数字阈值--高高报警
					pItemResult->m_sDataThreadHoldLL = pBelItem->m_sDataThreadHoldLL;     //数字阈值--低低报警
					pItemResult->m_sDataThreadHoldH = pBelItem->m_sDataThreadHoldH;      //数字阈值--高报警
					pItemResult->m_sDataThreadHoldL = pBelItem->m_sDataThreadHoldL;      //数字阈值--低报警
					pItemResult->m_sTaskExecGuid = sTaskExecGuid;
					pItemResult->m_nDevType = pBelItem->m_nDevType;//设备类型枚举  0 本体(传感器)  1云台
					pItemResult->m_nCheckType = pBelItem->m_nCheckType;//数据上报类型 0.调用返回  1.持续任务主动上报
					pItemResult->m_nDevTypeCode = pBelItem->m_nDevTypeCode;
					pItemResult->m_nBelong = vecRecord[i].value("BELONG").toInt();
					pItemResult->m_dActionTime = vecRecord[i].value("START_TIME").toDateTime();
					pItemResult->m_nAlarmLevel = vecRecord[i].value("ALARM_LEVEL").toInt();
					if (0 == pItemResult->m_nAlarmLevel)
					{
						pItemResult->m_nState = 0;
					}
					else
					{
						pItemResult->m_nState = 1;
					}
					//pItemResult->m_dValue = vecRecord[i].value("SENSOR_DATA").toDouble();
					//pItemResult->m_sDataDesc = vecRecord[i].value("SENSOR_DATA_DESC").toString();
					//pItemResult->m_dRealLocation = 0.5;
					pItemResult->m_nRollerNum = vecRecord[i].value("ROLLER_NO").toInt();
					pItemResult->m_sRollerDesc = vecRecord[i].value("ROLLER_CODE").toString();
					pItemResult->m_bIsShow = true;

					CItemResultCamera *pItemResultCam = (CItemResultCamera *)pItemResult;//相机结果
					pItemResultCam->m_sHttpUrl = vecRecord[i].value("RESULT_HTTP_URL").toString();
					//pItemResultCam->m_sIRUrl = "D:/RobotReult/Image/2001012024-04-26-10-57-32.jpg";
					//pItemResultCam->m_sAlarmUrl = "D:/RobotReult/Image/2001012024-04-26-10-57-32.jpg";
					pItemResultCam->m_sIRUrl = vecRecord[i].value("IR_URL").toString();
					pItemResultCam->m_sAlarmUrl = vecRecord[i].value("IR_URL").toString();

					pItemResultCam->m_dTempMax = vecRecord[i].value("TEMP_MAX").toDouble();
					pItemResultCam->m_dTempMin = vecRecord[i].value("TEMP_MIN").toDouble();
					pItemResultCam->m_dTempAverage = vecRecord[i].value("TEMP_AGV").toDouble();

					pItemComCotIrOne->m_ItemResult = pItemResult;

				}

				pTaskExecInfo->m_vecPolItemCom.push_back(pItemComCotIrOne);

				pItemComCotIrOne->m_pPolItem = new CPolItemCamer();;//所属巡检项 new新的
				pBelItem->copyData(pItemComCotIrOne->m_pPolItem);//copy巡检项的数据

				nIrOnce++;

			}
			if (nItemTypeCodeNow == enVoice && 0 == nVoiceOnce)
			{
				pItemComCotVoiceOne = new SCPolItemCom();
				pItemComCotVoiceOne->m_bIsAction = true;//是否已执行
				pItemComCotVoiceOne->m_bIsSave = true;//是否已经保存到数据库
				pItemComCotVoiceOne->m_bIsShow = true;//是否已经在界面上显示


				pItemComCotVoiceOne->m_pPolPoint = new CPolPoint();//所属巡检点 new新的
				pBelPoint->copyData(pItemComCotVoiceOne->m_pPolPoint);//copy巡检点pPolPoint1的数据
				//巡检结果
				{
					CItemResultBase *pItemResult = new CItemResultCamera();
					pItemResult->m_sItemResultGuid = vecRecord[i].value("POINT_GUID").toString();
					pItemResult->m_sPolAreaGuid = pPolArea->m_sPolAreaGuid;
					pItemResult->m_sPointGuid = sBelPointGuid;
					pItemResult->m_sItemGuid = sBelItemGuid;
					pItemResult->m_sTaskGuid = createGuid();
					pItemResult->m_sTemplateGuid = sTemplateFixedID;
					pItemResult->m_sStartTime = vecRecord[i].value("START_TIME").toDateTime().toString("yyyy/MM/dd hh:mm:ss");//执行时间
					pItemResult->m_sTaskName = A2T("巡检任务");
					pItemResult->m_sPointName = pBelPoint->m_sPointName;
					pItemResult->m_sItemName = pBelItem->m_sItemName;
					pItemResult->m_sGuid = sSceneGuidNow;
					pItemResult->m_sDataThreadHoldHH = pBelItem->m_sDataThreadHoldHH;     //数字阈值--高高报警
					pItemResult->m_sDataThreadHoldLL = pBelItem->m_sDataThreadHoldLL;     //数字阈值--低低报警
					pItemResult->m_sDataThreadHoldH = pBelItem->m_sDataThreadHoldH;      //数字阈值--高报警
					pItemResult->m_sDataThreadHoldL = pBelItem->m_sDataThreadHoldL;      //数字阈值--低报警
					pItemResult->m_sTaskExecGuid = sTaskExecGuid;
					pItemResult->m_nDevType = pBelItem->m_nDevType;//设备类型枚举  0 本体(传感器)  1云台
					pItemResult->m_nCheckType = pBelItem->m_nCheckType;//数据上报类型 0.调用返回  1.持续任务主动上报
					pItemResult->m_nDevTypeCode = pBelItem->m_nDevTypeCode;
					pItemResult->m_nBelong = vecRecord[i].value("BELONG").toInt();
					pItemResult->m_dActionTime = vecRecord[i].value("START_TIME").toDateTime();
					pItemResult->m_nAlarmLevel = vecRecord[i].value("ALARM_LEVEL").toInt();
					if (0 == pItemResult->m_nAlarmLevel)
					{
						pItemResult->m_nState = 0;
					}
					else
					{
						pItemResult->m_nState = 1;
					}
					//pItemResult->m_dValue = vecRecord[i].value("SENSOR_DATA").toDouble();
					//pItemResult->m_sDataDesc = vecRecord[i].value("SENSOR_DATA_DESC").toString();
					//pItemResult->m_dRealLocation = 0.5;
					pItemResult->m_nRollerNum = vecRecord[i].value("ROLLER_NO").toInt();
					pItemResult->m_sRollerDesc = vecRecord[i].value("ROLLER_CODE").toString();
					pItemResult->m_bIsShow = true;

					CItemResultCamera *pItemResultCam = (CItemResultCamera *)pItemResult;//相机结果
					pItemResultCam->m_sHttpUrl = vecRecord[i].value("RESULT_HTTP_URL").toString();
					pItemResultCam->m_sIRUrl = "D:/RobotReult/Image/2001012024-04-26-10-57-32.jpg";
					pItemResultCam->m_sAlarmUrl = "D:/RobotReult/Image/2001012024-04-26-10-57-32.jpg";

					pItemResultCam->m_dValue = vecRecord[i].value("VOICE_DATA").toDouble();

					pItemComCotVoiceOne->m_ItemResult = pItemResult;

				}

				pTaskExecInfo->m_vecPolItemCom.push_back(pItemComCotVoiceOne);

				pItemComCotVoiceOne->m_pPolItem = new CPolItemCamer();;//所属巡检项 new新的
				pBelItem->copyData(pItemComCotVoiceOne->m_pPolItem);//copy巡检项的数据

				nVoiceOnce++;
			}
			if (nItemTypeCodeNow == enCamer && 0 == nImageOnce)
			{
				pItemComCotImageOne = new SCPolItemCom();
				pItemComCotImageOne->m_bIsAction = true;//是否已执行
				pItemComCotImageOne->m_bIsSave = true;//是否已经保存到数据库
				pItemComCotImageOne->m_bIsShow = true;//是否已经在界面上显示


				pItemComCotImageOne->m_pPolPoint = new CPolPoint();//所属巡检点 new新的
				pBelPoint->copyData(pItemComCotImageOne->m_pPolPoint);//copy巡检点pPolPoint1的数据
				//巡检结果
				{
					CItemResultBase *pItemResult = new CItemResultCamera();
					pItemResult->m_sItemResultGuid = vecRecord[i].value("POINT_GUID").toString();
					pItemResult->m_sPolAreaGuid = pPolArea->m_sPolAreaGuid;
					pItemResult->m_sPointGuid = sBelPointGuid;
					pItemResult->m_sItemGuid = sBelItemGuid;
					pItemResult->m_sTaskGuid = createGuid();
					pItemResult->m_sTemplateGuid = sTemplateFixedID;
					pItemResult->m_sStartTime = vecRecord[i].value("START_TIME").toDateTime().toString("yyyy/MM/dd hh:mm:ss");//执行时间
					pItemResult->m_sTaskName = A2T("巡检任务");
					pItemResult->m_sPointName = pBelPoint->m_sPointName;
					pItemResult->m_sItemName = pBelItem->m_sItemName;
					pItemResult->m_sGuid = sSceneGuidNow;
					pItemResult->m_sDataThreadHoldHH = pBelItem->m_sDataThreadHoldHH;     //数字阈值--高高报警
					pItemResult->m_sDataThreadHoldLL = pBelItem->m_sDataThreadHoldLL;     //数字阈值--低低报警
					pItemResult->m_sDataThreadHoldH = pBelItem->m_sDataThreadHoldH;      //数字阈值--高报警
					pItemResult->m_sDataThreadHoldL = pBelItem->m_sDataThreadHoldL;      //数字阈值--低报警
					pItemResult->m_sTaskExecGuid = sTaskExecGuid;
					pItemResult->m_nDevType = pBelItem->m_nDevType;//设备类型枚举  0 本体(传感器)  1云台
					pItemResult->m_nCheckType = pBelItem->m_nCheckType;//数据上报类型 0.调用返回  1.持续任务主动上报
					pItemResult->m_nDevTypeCode = pBelItem->m_nDevTypeCode;
					pItemResult->m_nBelong = vecRecord[i].value("BELONG").toInt();
					pItemResult->m_dActionTime = vecRecord[i].value("START_TIME").toDateTime();
					pItemResult->m_nAlarmLevel = vecRecord[i].value("ALARM_LEVEL").toInt();
					if (0 == pItemResult->m_nAlarmLevel)
					{
						pItemResult->m_nState = 0;
					}
					else
					{
						pItemResult->m_nState = 1;
					}
					//pItemResult->m_dValue = vecRecord[i].value("SENSOR_DATA").toDouble();
					//pItemResult->m_sDataDesc = vecRecord[i].value("SENSOR_DATA_DESC").toString();
					//pItemResult->m_dRealLocation = 0.5;
					pItemResult->m_nRollerNum = vecRecord[i].value("ROLLER_NO").toInt();
					pItemResult->m_sRollerDesc = vecRecord[i].value("ROLLER_CODE").toString();
					pItemResult->m_bIsShow = true;

					CItemResultCamera *pItemResultCam = (CItemResultCamera *)pItemResult;//相机结果
					pItemResultCam->m_sHttpUrl = vecRecord[i].value("RESULT_HTTP_URL").toString();
					pItemResultCam->m_sIRUrl = vecRecord[i].value("IR_URL").toString();
					pItemResultCam->m_sAlarmUrl = vecRecord[i].value("IR_URL").toString();


					pItemComCotImageOne->m_ItemResult = pItemResult;

				}

				pTaskExecInfo->m_vecPolItemCom.push_back(pItemComCotImageOne);

				pItemComCotImageOne->m_pPolItem = new CPolItemCamer();;//所属巡检项 new新的
				pBelItem->copyData(pItemComCotImageOne->m_pPolItem);//copy巡检项的数据

				nImageOnce++;
			}
		}


		//第三遍实际添加连续检测数据
		for (int i = 0; i < vecRecord.size(); i++)
		{
			//非连续检测直接PASS
			if (vecRecord[i].value("IS_COTDET").toInt() == 0)
			{
				continue;
			}

			int nItemTypeCodeNow = vecRecord[i].value("ITEM_TYPE_CODE").toInt();

			QString sBelPointGuid = vecRecord[i].value("POINT_GUID").toString();//巡检点GUID
			QString sTemplateFixedID = vecRecord[i].value("TEMPLATE_GUID").toString();//模板GUID
			QString sBelItemGuid = vecRecord[i].value("ITEM_GUID").toString();//巡检项Guid
			//找到对应巡检点
			CPolPoint *pBelPoint = nullptr;
			if (pPolArea->m_mapPolPoint.contains(sBelPointGuid))
			{
				pBelPoint = pPolArea->m_mapPolPoint[sBelPointGuid];
			}
			if (pBelPoint == nullptr)
			{
				continue;
			}

			//找到对应巡检项
			CPolItem *pBelItem = nullptr;
			if (pBelPoint->m_mapPolItem.contains(sBelItemGuid))
			{
				pBelItem = pBelPoint->m_mapPolItem[sBelItemGuid];
			}
			if (pBelItem == nullptr)
			{
				continue;
			}

			//巡检结果
			{
				CItemResultBase *pItemResult = new CItemResultCamera();
				pItemResult->m_sItemResultGuid = vecRecord[i].value("POINT_GUID").toString();
				pItemResult->m_sPolAreaGuid = pPolArea->m_sPolAreaGuid;
				pItemResult->m_sPointGuid = sBelPointGuid;
				pItemResult->m_sItemGuid = sBelItemGuid;
				pItemResult->m_sTaskGuid = createGuid();
				pItemResult->m_sTemplateGuid = sTemplateFixedID;
				pItemResult->m_sStartTime = vecRecord[i].value("START_TIME").toDateTime().toString("yyyy/MM/dd hh:mm:ss");//执行时间
				pItemResult->m_sTaskName = A2T("巡检任务");
				pItemResult->m_sPointName = pBelPoint->m_sPointName;
				pItemResult->m_sItemName = pBelItem->m_sItemName;
				pItemResult->m_sGuid = sSceneGuidNow;
				pItemResult->m_sDataThreadHoldHH = pBelItem->m_sDataThreadHoldHH;     //数字阈值--高高报警
				pItemResult->m_sDataThreadHoldLL = pBelItem->m_sDataThreadHoldLL;     //数字阈值--低低报警
				pItemResult->m_sDataThreadHoldH = pBelItem->m_sDataThreadHoldH;      //数字阈值--高报警
				pItemResult->m_sDataThreadHoldL = pBelItem->m_sDataThreadHoldL;      //数字阈值--低报警
				pItemResult->m_sTaskExecGuid = sTaskExecGuid;
				pItemResult->m_nDevType = pBelItem->m_nDevType;//设备类型枚举  0 本体(传感器)  1云台
				pItemResult->m_nCheckType = pBelItem->m_nCheckType;//数据上报类型 0.调用返回  1.持续任务主动上报
				pItemResult->m_nDevTypeCode = pBelItem->m_nDevTypeCode;
				pItemResult->m_nBelong = vecRecord[i].value("BELONG").toInt();
				pItemResult->m_dActionTime = vecRecord[i].value("START_TIME").toDateTime();
				pItemResult->m_nAlarmLevel = vecRecord[i].value("ALARM_LEVEL").toInt();
				if (0 == pItemResult->m_nAlarmLevel)
				{
					pItemResult->m_nState = 0;
				}
				else
				{
					pItemResult->m_nState = 1;
				}
				//pItemResult->m_dValue = vecRecord[i].value("SENSOR_DATA").toDouble();
				//pItemResult->m_sDataDesc = vecRecord[i].value("SENSOR_DATA_DESC").toString();
				//pItemResult->m_dRealLocation = 0.5;
				pItemResult->m_nRollerNum = vecRecord[i].value("ROLLER_NO").toInt();
				pItemResult->m_sRollerDesc = vecRecord[i].value("ROLLER_CODE").toString();
				pItemResult->m_bIsShow = true;

				CItemResultCamera *pItemResultCam = (CItemResultCamera *)pItemResult;//相机结果
				pItemResultCam->m_sHttpUrl = vecRecord[i].value("RESULT_HTTP_URL").toString();
				pItemResultCam->m_sIRUrl = vecRecord[i].value("IR_URL").toString();
				pItemResultCam->m_sAlarmUrl = vecRecord[i].value("IR_URL").toString();


				if (nItemTypeCodeNow == enIR)//红外
				{
					pItemResultCam->m_dTempMax = vecRecord[i].value("TEMP_MAX").toDouble();
					pItemResultCam->m_dTempMin = vecRecord[i].value("TEMP_MIN").toDouble();
					pItemResultCam->m_dTempAverage = vecRecord[i].value("TEMP_AGV").toDouble();

					pItemComCotIrOne->m_vecItemResult.push_back(pItemResult);
				}
				else if (nItemTypeCodeNow == enVoice)//vecRecord[i].value("VOICE_DATA").toString()
				{
					pItemResultCam->m_dValue = vecRecord[i].value("VOICE_DATA").toDouble();

					pItemComCotVoiceOne->m_vecItemResult.push_back(pItemResult);
				}
				else if (nItemTypeCodeNow == enCamer)
				{
					pItemComCotImageOne->m_vecItemResult.push_back(pItemResult);
				}

			}

		}

	}


	//释放
	delete pPolArea;
	pPolArea = nullptr;

}

//获取连续检测某类型指定Map数据
void CPdfRptDataPkg::getCotAppointMapData(QMap<int, QVector<CSingleCotDetInfo>> &mapCotAppoint, QVector<CSingleCotDetInfo> &vecCotDetInfo, EDevTypeCode eItemCode)
{
	for (int i = 0; i < vecCotDetInfo.size(); i++)
	{
		if (vecCotDetInfo[i].eItemCode != eItemCode)
		{
			continue;
		}

		if (mapCotAppoint.contains(vecCotDetInfo[i].m_nRollerCode))
		{
			// 获取对应的 QVector
			QVector<CSingleCotDetInfo> &vecData = mapCotAppoint[vecCotDetInfo[i].m_nRollerCode];
			vecData.append(vecCotDetInfo[i]);
		}
		else
		{
			QVector<CSingleCotDetInfo> vecData;
			vecData.append(vecCotDetInfo[i]);
			mapCotAppoint.insert(vecCotDetInfo[i].m_nRollerCode, vecData);
		}
	}
}
//获取机器人归属皮带
QString CPdfRptDataPkg::getRobBelongBelt(QString sRobSceneGuid)
{
	QString sBeltName = "";
	QString sErrMsg = "";
	//CSqlOperPub::instance().selectBeltNameBySceneID(sRobSceneGuid, sBeltName, sErrMsg);
	return sBeltName;
}

//获取球机场景Guid(根据归属皮带名称)
QString CPdfRptDataPkg::getBaCamSceneGuid(QString sBelBeltName)
{
	//根据皮带名称(8#皮带)和SMALL_SCENE_TYPE是3来筛选出球机测温的场景GUID
	QString sBaCamSceneGuid = "";
	QString sErrMsg = "";
	//CSqlOperPub::instance().getBaCamSceneGuid(sBelBeltName, sBaCamSceneGuid, sErrMsg);
	return sBaCamSceneGuid;
}
